﻿using System;
using System.Web.UI;
using ASPNETVN.PORTAL.Components.UI.DataTypes;

namespace ASPNETVN.PORTAL.Components.Configuration.Settings
{
    public class PortalSettingItem : IComparable
    {
        private string _Name = string.Empty;
        private readonly BaseDataType _DataType;
        private string _Description = string.Empty;
        private int _MaxValue;
        private int _MinValue;
        private int _SortOrder;
        private bool _Required;
        private PortalSettingItemGroup _PortalSettingItemGroup = PortalSettingItemGroup.Module_Special;


        public PortalSettingItem(BaseDataType datatype, string value)
        {
            this._DataType = datatype;
            this._DataType.Value = value;
        }

        public string Name
        {
            get { return _Name; }
            set { _Name = value; }
        }

        public BaseDataType DataType
        {
            get { return _DataType; }
        }

        public string Description
        {
            get { return _Description; }
            set { _Description = value; }
        }

        public int MaxValue
        {
            get { return _MaxValue; }
            set { _MaxValue = value; }
        }

        public int MinValue
        {
            get { return _MinValue; }
            set { _MinValue = value; }
        }

        public int SortOrder
        {
            get { return _SortOrder; }
            set { _SortOrder = value; }
        }

        public bool Required
        {
            get { return _Required; }
            set { _Required = value; }
        }

        public string GroupDescription
        {
            get
            {
                switch (this._PortalSettingItemGroup)
                {
                    case PortalSettingItemGroup.None:
                        return "Generic settings";

                    case PortalSettingItemGroup.Theme_Layout:
                        return "Theme and layout settings";

                    case PortalSettingItemGroup.Security_User:
                        return "Users and Security settings";

                    case PortalSettingItemGroup.Culture:
                        return "Culture settings";

                    case PortalSettingItemGroup.Button_Display:
                        return "Buttons and Display settings";

                    case PortalSettingItemGroup.Module_Special:
                        return "Specific Module settings";

                    case PortalSettingItemGroup.Meta:
                        return "Meta settings";

                    case PortalSettingItemGroup.Misc:
                        return "Miscellaneous settings";

                    case PortalSettingItemGroup.Navigation:
                        return "Navigation settings";

                    case PortalSettingItemGroup.Custom_User:
                        return "Custom User Settings";
                }
                return "Settings";
            }
        }

        public PortalSettingItemGroup Group
        {
            get { return this._PortalSettingItemGroup; }
            set { this._PortalSettingItemGroup = value; }
        }

        /// <summary>
        /// EditControl
        /// </summary>
        public Control EditControl
        {
            get
            {
                return this._DataType.EditControl;
            }
            set
            {
                this._DataType.EditControl = value;
            }
        }


        #region IComparable Members

        public int CompareTo(object value)
        {
            if (value == null) return 1;
            int compareOrder = ((ModuleSettingItem)value).SortOrder;
            if (this.SortOrder == compareOrder) return 0;
            if (this.SortOrder < compareOrder) return -1;
            if (this.SortOrder > compareOrder) return 1;
            return 0;
        }

        #endregion
    }
}
